#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> sortArrayByParity(vector<int>& nums) {
        int n = nums.size();
        int left = 0, right = n - 1;
        while (left < right)
        {
            while (left < right && nums[left] % 2 == 0) left++;
            while (left < right && nums[right] % 2 == 1) right--;

            swap(nums[left++], nums[right--]);
        }
        return nums;
    }
};

class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int m = s.size(), n = p.size();
        int hash1[26] = { 0 }, hash2[26] = { 0 };
        for (auto e : p) hash2[e - 'a']++;
        int cnt = 0;

        vector<int> ret;
        for (int left = 0, right = 0; right < m; right++)
        {
            hash1[s[right] - 'a']++;
            if (hash1[s[right] - 'a'] <= hash2[s[right] - 'a']) cnt++;

            if (right - left + 1 == n)
            {
                if (cnt == n) ret.push_back(left);
                if (hash1[s[left] - 'a'] <= hash2[s[left] - 'a']) cnt--;
                hash1[s[left++] - 'a']--;
            }
        }
        return ret;
    }
};